ubuntu中编写shell脚本开机自动启动(推荐)

您所在的位置:网站首页 ubuntu1804 开机自动执行脚本 ubuntu中编写shell脚本开机自动启动(推荐)

ubuntu中编写shell脚本开机自动启动(推荐)

2024-07-17 04:05| 来源: 网络整理| 查看: 265

1.进入终端输入

创建一个后缀为.sh的脚本文件

touch test.sh

编辑脚本

vim test.sh

test.sh编写脚本内容

2.编写test.sh脚本

#!/bin/bash ### BEGIN INIT INFO # Provides: test # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: start test # Description: start test ### END INIT INFO #此处编写脚本内容 cd /home/Desktop/ ./test.sh exit 0

     a. 以#!/bin/bash开头 中间写脚本内容 exit 0 结尾

     b.注释信息不可少,不然不生效

3.移动test.sh文件到/etc/init.d目录下

移动文件

sudo mv test.sh /etc/init.d/

保存成功以后,设置文本权限,否则不生效

chmod 755 test.sh

3、将命令脚本添加到启动脚本中去

sudo update-rc.d test.sh defaults

4、如需移除自启动,运行以下命令

cd /etc/init.dsudo update-rc.d -f test.sh remove

 

5.这样一个开机自动化脚本就完成咯


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3